<template>
  <div class="new_body">
    <div
      class="new_item"
      v-for="(item, i) in dataList"
      :key="i"
      @click="$router.push({ name: 'NewsContent', query: { id: item.id } })"
    >
      <div class="new_item_block">
        <div class="new_item_title">{{ item.title }}</div>
        <div class="new_item_dec">
          <span class="new_item_from">{{ item.author }}</span>
          <span class="new_item_eye">{{ item.clickNumber }}</span>
          <span class="new_item_date">{{ item.publishDate }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import keepScroll from "vue-infinite-loading";
export default {
  data() {
    return {
      dataList: [],
      nowPage: 0,
      nownum: 0,
      allCount: null
    };
  },
  components: {
    keepScroll
  },

  methods: {
    scroll() {
      this.$axios
        .get("api/news/list", {
        })
        .then(({ data }) => {
          data.data.forEach(item => {
           this.dataList.push(item);
          });
          this.dataList.sort(function(a, b) {
            return a.publishDate < b.publishDate ? 1 : -1;
          });
        })
        .catch(error => {
          this.$msgBox.show("网络异常,请刷新", "error", 250, 60);
        });
    }
  },
  mounted() {
    this.scroll();
  }
};
</script>

<style scoped>
.new_body {
  max-width: 1000px;
  margin: 0 auto;
}
.new_item {
  padding: 10px;
  border-bottom: 1px solid var(--borderColor);
  display: flex;
  transition: background 1s;
}
.new_item:hover {
  background-color: skyblue;
}
.new_item_block {
  cursor: pointer;
}
.new_item_block:nth-child(1) {
  flex: 1;
}
.new_item_block:nth-child(2) {
  display: flex;
  justify-content: center;
  align-items: center;
}
.new_item_title {
  font-size: 20px;
  margin: 5px 0;
}
.new_item_dec {
  color: gray;
  font-size: 13px;
}
.new_item_dec span {
  position: relative;
  padding-left: 20px;
  padding-right: 10px;
}
.new_item_dec span::before {
  position: absolute;
  content: "";
  width: 20px;
  height: 20px;
  left: 0;
  bottom: 0;
  margin: auto;
}
.new_item_dec span:nth-child(1)::before {
  background-image: url("");
}
.new_item_dec span:nth-child(2)::before {
  background-image: url("");
}
.new_item_dec span:nth-child(3)::before {
  background-image: url("");
}
.new_item_go {
  color: gray;
  font-size: 13px;
  font-weight: bold;
}
</style>
